﻿namespace HiMap.Carto
{
    using HiMap.Base;
    using HiMap.Style;
    using System;
    using System.Drawing;

    public class PolylineStyleClass : HiMapPtrClass, IPolylineStyle, IStyle, IHiMapPtr
    {
        public PolylineStyleClass()
        {
            base.m_InPtr = HiMap.Carto.VC.KWG_LINESTYLE_CREATE();
            base.m_Used = false;
        }

        public PolylineStyleClass(int SID)
        {
            base.m_InPtr = HiMap.Carto.VC.KWG_LINESTYLE_FROMSID(SID);
            if (base.m_InPtr == 0)
            {
                base.m_InPtr = HiMap.Carto.VC.KWG_LINESTYLE_FROMSID(0);
            }
            base.m_Used = false;
        }

        internal PolylineStyleClass(int InPtr, bool Used)
        {
            base.m_InPtr = InPtr;
            base.m_Used = Used;
        }

        ~PolylineStyleClass()
        {
            if (!base.m_Used && (base.m_InPtr != 0))
            {
                HiMap.Carto.VC.KWG_LINESTYLE_DELETE(base.m_InPtr);
            }
        }

        double IPolylineStyle.GetLineStyleScale()
        {
            double scale = 0;
            HiMap.Carto.VC.KWG_LINESTYLE_GET_SCALE(base.m_InPtr, ref scale);
            return scale;
        }

        Color IPolylineStyle.GetLineSymbolColor(int nSymbol)
        {
            int num = HiMap.Carto.VC.KWG_LINESTYLE_GET_SYMBOL(base.m_InPtr, nSymbol);
            Color black = Color.Black;
            if (num != 0)
            {
                int num2 = HiMap.Carto.VC.KWG_LINESYMBOL_GET_COLOR(num);
                int red = num2 % 0x100;
                int green = (num2 % 0x10000) / 0x100;
                int blue = num2 / 0x10000;
                black = Color.FromArgb(red, green, blue);
            }
            return black;
        }

        int IPolylineStyle.GetLineSymbolWidth(int nSymbol)
        {
            int num = HiMap.Carto.VC.KWG_LINESTYLE_GET_SYMBOL(base.m_InPtr, nSymbol);
            if (num == 0)
            {
                return 0;
            }
            return HiMap.Carto.VC.KWG_LINESYMBOL_GET_WIDTH(num);
        }

        void IPolylineStyle.SetLineStyleScale(double scale)
        {
            HiMap.Carto.VC.KWG_LINESTYLE_SET_SCALE(base.m_InPtr, scale);
        }

        void IPolylineStyle.SetLineSymbolColor(int nSymbol, Color color)
        {
            int num = HiMap.Carto.VC.KWG_LINESTYLE_GET_SYMBOL(base.m_InPtr, nSymbol);
            if (num != 0)
            {
                int num2 = (color.R + (color.G * 0x100)) + ((color.B * 0x100) * 0x100);
                HiMap.Carto.VC.KWG_LINESYMBOL_SET_COLOR(num, num2);
            }
        }

        void IPolylineStyle.SetLineSymbolWidth(int nSymbol, int nWidth)
        {
            int num = HiMap.Carto.VC.KWG_LINESTYLE_GET_SYMBOL(base.m_InPtr, nSymbol);
            if (num != 0)
            {
                HiMap.Carto.VC.KWG_LINESYMBOL_SET_WIDTH(num, nWidth);
            }
        }

        int IPolylineStyle.LineSymbolCount
        {
            get
            {
                return HiMap.Carto.VC.KWG_LINESTYLE_GET_SYMBOL_COUNT(base.m_InPtr);
            }
        }

        StyleType IStyle.Type
        {
            get
            {
                return StyleType.PolylineStyle;
            }
        }
    }
}

